home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / kaffe-0.2 / kaffe / constants.h < prev    next >
C/C++ Source or Header  |  1996-02-12  |  2KB  |  88 lines

  1. /*
  2.  * constants.h
  3.  * Manage constants.
  4.  *
  5.  * Copyright (c) 1996 Systems Architecture Research Centre,
  6.  *           City University, London, UK.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
  12.  */
  13.  
  14. /* COPYRIGHT */
  15.  
  16. #ifndef __constant_h
  17. #define __constant_h
  18.  
  19. #include <stdio.h>
  20. #include "object.h"
  21. #include "file.h"
  22.  
  23. /*
  24.  * Constant pool definitions.
  25.  */
  26. #define    CONSTANT_Class            7
  27. #define    CONSTANT_Fieldref        9
  28. #define    CONSTANT_Methodref        10
  29. #define    CONSTANT_InterfaceMethodref    11
  30. #define    CONSTANT_String            8
  31. #define    CONSTANT_Integer        3
  32. #define    CONSTANT_Float            4
  33. #define    CONSTANT_Long            5
  34. #define    CONSTANT_Double            6
  35. #define    CONSTANT_NameAndType        12
  36. #define    CONSTANT_Utf8            1
  37. #define    CONSTANT_Unicode        2
  38.  
  39. #define    CONSTANT_Unknown        0
  40. #define    CONSTANT_Chararray        128
  41.  
  42. typedef u2    constIndex;
  43.  
  44. typedef struct _constants {
  45.     u2    size;
  46.     u1*    tags;
  47.     u4*    data;
  48. } constants;
  49.  
  50. #define    STRHASHSZ        128
  51.  
  52. typedef struct _strconst {
  53.     struct _strconst*    next;
  54.     struct _stringClass*    string;
  55.     object            obj;
  56.     char            data[0];
  57. } strconst;
  58.  
  59. #define    STRING_DATA2BASE(i)    (strconst*)(((int)i) - (sizeof(object)+sizeof(strconst*)+sizeof(strconst*)))
  60. #define    STRING_OBJ2DATA(i)    (char*)(((int)i) + sizeof(object))
  61.  
  62. typedef struct _strpair {
  63.     struct _strpair*    next;
  64.     uint32            hash;
  65.     char*            s1;
  66.     char*            s2;
  67. } strpair;
  68.  
  69. /*
  70.  * Macros to take constant pools apart.
  71.  */
  72. #define    METHODREF_CLASS(idx, pool)        (pool->data[idx] & 0xFFFF)
  73. #define    METHODREF_NAMEANDTYPE(idx, pool)    (pool->data[idx] >> 16)
  74. #define    CLASS_NAME(idx, pool)            (pool->data[idx])
  75. #define    FIELDREF_CLASS(idx, pool)        METHODREF_CLASS(idx, pool)
  76. #define    FIELDREF_NAMEANDTYPE(idx, pool)        METHODREF_NAMEANDTYPE(idx, pool)
  77. #define    NAMEANDTYPE_NAME(idx, pool)        METHODREF_CLASS(idx, pool)
  78. #define    NAMEANDTYPE_SIGNATURE(idx, pool)    METHODREF_NAMEANDTYPE(idx, pool)
  79. #define    STRING_NAME(idx, pool)            CLASS_NAME(idx, pool)
  80.  
  81. constants*    readConstantPool(classFile*);
  82.  
  83. char*        addStringConstant(strconst*);
  84. strpair*    addStringConstantPair(char*, char*);
  85. strpair*    lookupStringPair(char*, char*);
  86.  
  87. #endif
  88.